using System;
using Glue;
using Xunit;

namespace GlueTests.MapperTests
{
    public class When_mapping_property_with_different_types_and_converter_is_added
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;
        private readonly DomainPerson domainPerson;
        private readonly GuiPerson guiPerson;

        public class GuiPerson
        {
            public String Id { get; set; }
        }

        public class DomainPerson
        {
            public int Id{ get; set; }
        }

        public When_mapping_property_with_different_types_and_converter_is_added()
        {
            domainPerson = new DomainPerson();
            guiPerson = new GuiPerson();
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.AddConverter(Converting.BetweenIntAndString());
            mapping.Relate(master => master.Id, t => t.Id);
        }

        [Fact]
        public void Should_map_relation_towards_right()
        {
            domainPerson.Id = 3;
            mapping.Map(domainPerson, guiPerson);
            Assert.Equal("3", guiPerson.Id);
        }

        [Fact]
        public void Should_map_relation_towards_left()
        {
            guiPerson.Id = "3";
            mapping.Map(guiPerson, domainPerson);
            Assert.Equal(3, domainPerson.Id);
        }
    }
}